package cn.steam.bar.service.impl;

import cn.steam.bar.dao.WeaponDao;
import cn.steam.bar.entity.Weapon;
import cn.steam.bar.model.WeaponCreateModel;
import cn.steam.bar.model.WeaponVO;
import cn.steam.bar.service.WeaponService;
import cn.steam.bar.util.CopyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhang jintao on 2022/05/11
 **/
@Service
public class WeaponServiceImpl implements WeaponService {

    private final Logger logger = LoggerFactory.getLogger(WeaponServiceImpl.class);

    @Autowired
    WeaponDao weaponDao;

    @Override
    public WeaponVO getById(Integer id) {
        return CopyUtils.copy(weaponDao.findById(id).orElse(null), WeaponVO.class);
    }

    @Override
    public Boolean delete(Integer id) {
        weaponDao.deleteById(id);
        return true;
    }

    @Override
    public Boolean save(WeaponCreateModel model) {

        Weapon weapon = Weapon.builder()
                .name(model.getName())
                .type(model.getType()).build();
        Weapon res = weaponDao.save(weapon);
        logger.info("保存成功，res：{}", res);
        return true;

    }
}
